import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Question16 {
    static int[][] dist = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

    public static void dfs(int x, int y, int[][] nums, int[][] vis) {
        int row = nums.length;
        int col = nums[0].length;

        for (int i = 0; i < 4; i++) {
            int xx = x + dist[i][0];
            int yy = y + dist[i][1];

            if (xx >= 0 && xx < row && yy >= 0 && yy < col) {
                if (nums[xx][yy] == 1 && vis[xx][yy] == 0) {
                    vis[xx][yy] = 1;
                    dfs(xx, yy, nums, vis);
                }
            }
        }

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        int[][] arrs = new int[n][2];

        int row = 0;
        int col = 0;

        for (int i = 0; i < n; i++) {
            arrs[i][0] = in.nextInt() - 1;
            arrs[i][1] = in.nextInt() - 1;

            row = Math.max(row, arrs[i][0] + 1);
            col = Math.max(col, arrs[i][1] + 1);
        }

        int[][] nums = new int[row][col];
        for (int i = 0; i < n; i++) {
            nums[arrs[i][0]][arrs[i][1]] = 1;
        }


        int time = 0;
        int tar = 0;
        while (true) {
            tar = 0;

            for (int i = 0; i < row; i++) {
                for (int j = 0; j < col; j++) {
                    if (nums[i][j] == 1) {
                        tar++;;
                    }
                }
            }

            int gg = 0;
            int[][] vis = new int[row][col];
            for (int i = 0; i < row; i++) {
                for (int j = 0; j < col; j++) {
                    if (nums[i][j] == 1) {
                        vis = new int[row][col];
                        vis[i][j] = 1;
                        dfs(i, j, nums, vis);
                        

                        gg = 1;
                        break;
                    }
                }

                if (gg == 1) {
                    break;
                }
            }


            for (int i = 0; i < row; i++) {
                for (int j = 0; j < col; j++) {
                    if (nums[i][j] == 1 && vis[i][j] == 0) {
                        gg = 0;
                        break;
                    }
                }

                if (gg == 0) {
                    break;
                }
            }

            if (gg == 1) {
                break;
            }

            for (int i = 0; i < row; i++) {
                for (int j = 0; j < col; j++) {
                    if (nums[i][j] == 1) {
                        if (i - 1 > 0) {
                            nums[i - 1][j] = 1;
                        }
                        if (i + 1 < row) {
                            nums[i + 1][j] = 1;
                        }
                        if (j - 1 > 0) {
                            nums[i][j - 1] = 1;
                        }
                        if (j + 1 < col) {
                            nums[i][j + 1] = 1;
                        }
                    }
                }
            }

            time++;
        }

        System.out.println(time);
    }
}